package com.itcast.chapter01;

import com.itcast.chapter01.annotation.RegisterAnnotation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * @author : zjj
 * @date : 2022/9/5 16:53
 */

@Component
public class Component01 {
    private static final Logger log = LoggerFactory.getLogger(Component01.class);

    @Autowired
    private ApplicationContext applicationContext;

    /**
     * 事件监听器
     * @param event
     */
    @EventListener
    public void add(UserRegisterSendSmsEvent event){
        log.debug("{},事件发生了",event);
    }

    /**
     * 注册事件发生
     */
    @RegisterAnnotation("sendEmail")
    public void register(){
        System.out.println("完成注册");
        applicationContext.publishEvent(new UserRegisterSendEmailEvent(applicationContext));
    }
}
